From: Florian Müllner Date: Fri, 4 Sep 2026 18:45:23 +0000 (+0200) Subject: messageList: Limit body/title length X-Git-Tag: archive/raspbian/50.5-1+rpi1^2~6^2^2~21 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=ad738eda9b7e76b6f4392bc326f9de0727e8b725;p=gnome-shell.git messageList: Limit body/title length The strings typically come from apps, and can therefore be of arbitrary length. Excessively long strings will end up ellsized, but they still affect performance when computing the Pango layout or searching for URLs, as those operate on the entire string. Address this by imposing a character limit on the strings, so that the amount of hidden characters to consider for URLs and layout is capped. The picked limits are based on sequences of "l", which should be more dense than any real text, and therefore guarantee that we only cut off invisible parts of the strings. Part-of: (cherry picked from commit 336a4b3c58ecef1b50e147eafa92fd21633604b1) --- diff --git a/js/ui/messageList.js b/js/ui/messageList.js index cf9e501d0..38ae640e6 100644 --- a/js/ui/messageList.js +++ b/js/ui/messageList.js @@ -30,6 +30,9 @@ const WIDTH_OFFSET_STACKED = 6; const HEIGHT_OFFSET_STACKED = 10; const HEIGHT_OFFSET_REDUCTION_STACKED = 1.4; +const MAX_TITLE_LENGTH = 150; +const MAX_BODY_LENGTH = 850; + export const URLHighlighter = GObject.registerClass( class URLHighlighter extends St.Label { _init(text = '', lineWrap, allowMarkup) { @@ -564,7 +567,7 @@ export const Message = GObject.registerClass({ } set title(text) { - this._titleText = text; + this._titleText = this._limitString(text, MAX_TITLE_LENGTH); const title = text ? Util.fixMarkup(text.replace(/\n/g, ' '), false) : ''; this.titleLabel.clutter_text.set_markup(title); this.notify('title'); @@ -575,7 +578,7 @@ export const Message = GObject.registerClass({ } set body(text) { - this._bodyText = text; + this._bodyText = this._limitString(text, MAX_BODY_LENGTH); this._bodyLabel.setMarkup(text ? text.replace(/\n/g, ' ') : '', this._useBodyMarkup); this.notify('body'); @@ -684,6 +687,15 @@ export const Message = GObject.registerClass({ } return super.vfunc_key_press_event(event); } + + _limitString(string, limit) { + const segmenter = new Intl.Segmenter(); + const graphemes = + Array.from(segmenter.segment(string)) + .splice(0, limit) + .map(o => o.segment); + return graphemes.join(''); + } }); export const NotificationMessage = GObject.registerClass(